define(["jquery","servers"], function ($,servers) {
    return Backbone.Model.extend({
        defaults: function () {
            return {
                defAdvertiserListRole:[{id:"agent",name:"代理商"},{id:"advertiser",name:"广告主"}],
                defAgentListRole:[{id:"agent",name:"代理商"}],
                defListStatus:[{ id: "1", name: "有效" },{ id: "2", name: "暂停中" }]
            };
        },
        getPageList:function(param){
            var self = this;
            var paramMap=servers.getPageParamMap();
            var newParam= $.ExtCommon.getMappingJson(param,paramMap);
            servers.user.pageList(newParam,function(res){
                var newJson=[];
                if(res.success){
                    newJson=$.map(res.data.list,function (info) {
                        var newInfo=  $.ExtCommon.getMappingJson(info,{
                            "id":"id","name":"name",userRole:"role","roleName":"roleName","status":"status",
                            customer:"actorId",customerName:"userName"
                        },true);
                        /*newInfo.status=newInfo.status.toString();
                        newInfo.isStart=newInfo.status==="1";
                        newInfo.statusName=newInfo.isStart?"启用":"停用";*/
                        return newInfo
                    });
                }else{
                    res.data={};
                }
                res.dataOriginal=res.data;
                res.data.list=newJson;
                self.set({dataPageList: res});
                self.trigger('bind:PageList');
            });
        },
        addInfo: function (json) {
            var self = this;
            var data=$.ExtCommon.getMappingJson(json, {
                "name":"name",password:"password", "status":"status", "userrole":"userRole",actorId:"customer"
            });
            if(json.userRole==="advertiser"){
                data.actorId=json.customer
            }
            servers.user.add(data, function (res) {
                self.set({dataSave: {isAdd: true, req: json, res: res}});
                self.trigger('save:Info');
            });
        },
        updateInfo: function (json) {
            var self = this;
            var data=$.ExtCommon.getMappingJson(json, {
                "id":"id","status":"status", "userrole":"userRole","name":"name",password:"password",actorId:"customer"
            });
            if(json.userRole==="advertiser"){
                data.actorId=json.customer
            }
            if(!$.ExtCommon.isCheckEmpty(json.passWordEdit)){data.password=json.passWordEdit}
            servers.user.update(data, function (res) {
                self.set({dataSave: {isAdd: false, req: json, res: res}});
                self.trigger('save:Info');
            });
        }
    });
});